<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>乐享购项目笔记 | SuJin博客</title><meta name="keywords" content="博客，SuJin"><meta name="author" content="SuJin"><meta name="copyright" content="SuJin"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="笔记3使用Spring Boot开发微服务，一、git代码相关1、安装git下载git客户端，右键桌面Git GUI&#x2F;bash Here。去bash， 1234567891011121314# 配置用户名git config --global user.name &quot;username&quot;  &#x2F;&#x2F;(名字，随意写)# 配置邮箱git config --global user.email">
<meta property="og:type" content="article">
<meta property="og:title" content="乐享购项目笔记">
<meta property="og:url" content="https://sujiesujie12456789.gitee.io/2021/11/30/%E4%B9%90%E4%BA%AB%E8%B4%AD%E9%A1%B9%E7%9B%AE/index.html">
<meta property="og:site_name" content="SuJin博客">
<meta property="og:description" content="笔记3使用Spring Boot开发微服务，一、git代码相关1、安装git下载git客户端，右键桌面Git GUI&#x2F;bash Here。去bash， 1234567891011121314# 配置用户名git config --global user.name &quot;username&quot;  &#x2F;&#x2F;(名字，随意写)# 配置邮箱git config --global user.email">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://picsum.photos/id/862/5451/3634">
<meta property="article:published_time" content="2021-11-30T02:58:11.000Z">
<meta property="article:modified_time" content="2022-03-30T13:11:11.928Z">
<meta property="article:author" content="SuJin">
<meta property="article:tag" content="博客，SuJin">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://picsum.photos/id/862/5451/3634"><link rel="shortcut icon" href="http://placekitten.com/350/200"><link rel="canonical" href="https://sujiesujie12456789.gitee.io/2021/11/30/%E4%B9%90%E4%BA%AB%E8%B4%AD%E9%A1%B9%E7%9B%AE/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '乐享购项目笔记',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-03-30 21:11:11'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 5.4.0"><link rel="alternate" href="/atom.xml" title="SuJin博客" type="application/atom+xml">
</head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="http://picsum.photos/id/859/1919/1919" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data is-center"><div class="data-item"><a href="/archives/"><div class="headline">文章</div><div class="length-num">11</div></a></div><div class="data-item"><a href="/tags/"><div class="headline">标签</div><div class="length-num">0</div></a></div><div class="data-item"><a href="/categories/"><div class="headline">分类</div><div class="length-num">0</div></a></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://picsum.photos/id/862/5451/3634')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">SuJin博客</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">乐享购项目笔记</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-11-30T02:58:11.000Z" title="发表于 2021-11-30 10:58:11">2021-11-30</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-03-30T13:11:11.928Z" title="更新于 2022-03-30 21:11:11">2022-03-30</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="乐享购项目笔记"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="笔记3"><a href="#笔记3" class="headerlink" title="笔记3"></a>笔记3</h1><h4 id="使用Spring-Boot开发微服务，"><a href="#使用Spring-Boot开发微服务，" class="headerlink" title="使用Spring Boot开发微服务，"></a>使用Spring Boot开发微服务，</h4><h2 id="一、git代码相关"><a href="#一、git代码相关" class="headerlink" title="一、git代码相关"></a>一、git代码相关</h2><h3 id="1、安装git"><a href="#1、安装git" class="headerlink" title="1、安装git"></a>1、安装git</h3><p>下载git客户端，右键桌面Git GUI/bash Here。去bash，</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"># 配置用户名</span><br><span class="line">git config --global user.name <span class="string">&quot;username&quot;</span>  <span class="comment">//(名字，随意写)</span></span><br><span class="line"># 配置邮箱</span><br><span class="line">git config --global user.email <span class="string">&quot;55333@qq.com&quot;</span> <span class="comment">// 注册账号时使用的邮箱</span></span><br><span class="line"># 配置ssh免密登录</span><br><span class="line">ssh-keygen -t rsa -C <span class="string">&quot;55333@qq.com&quot;</span></span><br><span class="line">三次回车后生成了密钥：公钥私钥</span><br><span class="line">cat ~/.ssh/id_rsa.pub</span><br><span class="line">也可以查看密钥</span><br><span class="line">浏览器登录码云后，个人头像上点设置--ssh公钥---随便填个标题---复制</span><br><span class="line">ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC6MWhGXSKdRxr1mGPZysDrcwABMTrxc8Va2IWZyIMMRHH9Qn/wy3PN2I9144UUqg65W0CDE/thxbOd</span><br><span class="line"># 测试</span><br><span class="line">ssh -T git<span class="meta">@gitee</span>.com</span><br><span class="line">测试成功，就可以无密给码云推送仓库了	</span><br></pre></td></tr></table></figure>

<h3 id="2、从0搭建"><a href="#2、从0搭建" class="headerlink" title="2、从0搭建"></a>2、从0搭建</h3><p><strong>1、码云操作：</strong></p>
<p>在码云新建仓库，仓库名gulimall，选择语言java，在.gitignore选中maven（就会忽略掉maven一些个人无需上传的配置文件），许可证选Apache-2.0，开发模型选生成/开发模型，开发时在dev分支，发布时在master分支，创建。</p>
<p><strong>2、IDEA操作：</strong></p>
<p>在IDEA中New–Project from version control–git–复制刚才项目的地址</p>
<p>IDEA然后New Module–Spring Initializer–com.atguigu.gulimall ， Artifact填 gulimall-product。Next—选择web（web开发），springcloud routing里选中openFeign（rpc调用）。依次创建出以下服务模块</p>
<ul>
<li><p>商品服务product</p>
</li>
<li><p>存储服务ware</p>
</li>
<li><p>订单服务order</p>
</li>
<li><p>优惠券服务coupon</p>
</li>
<li><p>用户服务member</p>
<h5 id="共同点："><a href="#共同点：" class="headerlink" title="共同点："></a>共同点：</h5><p>​        导入web和openFeign<br>​        group：com.atguigu.gulimall<br>​        Artifact：gulimall-XXX<br>​        每一个服务，包名com.atguigu.gulimall.XXX{product/order/ware/coupon/member}<br>​        模块名：gulimall-XXX<br>然后右下角显示了springboot的service选项，选择他。从某个项目粘贴个pom.xml粘贴到项目目录，修改他在maven窗口刷新，并点击+号，找到刚才的pom.xml添加进来，发现多了个root。这样比如运行root的clean命令，其他项目也一起clean了。</p>
</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">&lt;?xml version=<span class="string">&quot;1.0&quot;</span> encoding=<span class="string">&quot;UTF-8&quot;</span>?&gt;</span><br><span class="line">&lt;project xmlns=<span class="string">&quot;http://maven.apache.org/POM/4.0.0&quot;</span> xmlns:xsi=<span class="string">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span><br><span class="line">	xsi:schemaLocation=<span class="string">&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;</span>&gt;</span><br><span class="line">	&lt;modelVersion&gt;<span class="number">4.0</span><span class="number">.0</span>&lt;/modelVersion&gt;</span><br><span class="line">	&lt;groupId&gt;com.atguigu.gulimall&lt;/groupId&gt;</span><br><span class="line">	&lt;artifactId&gt;gulimall&lt;/artifactId&gt;</span><br><span class="line">	&lt;version&gt;<span class="number">0.0</span><span class="number">.1</span>-SNAPSHOT&lt;/version&gt;</span><br><span class="line">	&lt;name&gt;gulimall&lt;/name&gt;</span><br><span class="line">	&lt;description&gt;聚合服务&lt;/description&gt;</span><br><span class="line">	&lt;packaging&gt;pom&lt;/packaging&gt;</span><br><span class="line">	&lt;modules&gt;</span><br><span class="line">		&lt;<span class="keyword">module</span>&gt;gulimall-coupon&lt;/<span class="keyword">module</span>&gt;</span><br><span class="line">		&lt;<span class="keyword">module</span>&gt;gulimall-member&lt;/<span class="keyword">module</span>&gt;</span><br><span class="line">		&lt;<span class="keyword">module</span>&gt;gulimall-order&lt;/<span class="keyword">module</span>&gt;</span><br><span class="line">		&lt;<span class="keyword">module</span>&gt;gulimall-product&lt;/<span class="keyword">module</span>&gt;</span><br><span class="line">		&lt;<span class="keyword">module</span>&gt;gulimall-ware&lt;/<span class="keyword">module</span>&gt;</span><br><span class="line">	&lt;/modules&gt;</span><br><span class="line">&lt;/project&gt;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>3、忽略不重要文件</p>
<p>修改总项目的<code>.gitignore</code>，把小项目里的垃圾文件在提交的时候忽略掉，比如HELP.md。。。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">**/mvnw</span><br><span class="line">**/mvnw.cmd</span><br><span class="line">**/.mvn</span><br><span class="line">**/target/</span><br><span class="line">.idea</span><br><span class="line">**/.gitignore</span><br></pre></td></tr></table></figure>

<ol>
<li>在version control/local Changes，点击刷新看Unversioned Files，可以看到变化。</li>
<li>全选最后剩下21个文件，选择右键、Add to VCS</li>
<li><strong>在IDEA中安装插件：gitee，重启IDEA</strong></li>
<li>在D额fault changelist右键点击commit，去掉右面的勾选Perform code analysis、CHECK TODO，然后点击COMMIT，有个下拉列表，点击commit and push才会提交到云端。此时就可以在浏览器中看到了。</li>
<li><strong>commit只是保存更新到本地</strong></li>
<li><strong>push才是提交到gitee</strong></li>
</ol>
<h2 id="二、SpringCloud-Alibaba简介"><a href="#二、SpringCloud-Alibaba简介" class="headerlink" title="二、SpringCloud Alibaba简介"></a>二、SpringCloud Alibaba简介</h2><ul>
<li>注册中心：nacos</li>
<li>配置中心：nacos</li>
<li>网关：gateway</li>
<li>远程调用：netflix把feign闭源了，spring cloud开了个openFeign</li>
</ul>
<p>在common的pom.xml中加入</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">&lt;dependencyManagement&gt;</span><br><span class="line">    &lt;dependencies&gt;</span><br><span class="line">        &lt;dependency&gt;</span><br><span class="line">            &lt;groupId&gt;com.alibaba.cloud&lt;/groupId&gt;</span><br><span class="line">            &lt;artifactId&gt;spring-cloud-alibaba-dependencies&lt;/artifactId&gt;</span><br><span class="line">            &lt;version&gt;<span class="number">2.2</span><span class="number">.0</span>.RELEASE&lt;/version&gt;</span><br><span class="line">            &lt;type&gt;pom&lt;/type&gt;</span><br><span class="line">            &lt;scope&gt;<span class="keyword">import</span>&lt;/scope&gt;</span><br><span class="line">        &lt;/dependency&gt;</span><br><span class="line">    &lt;/dependencies&gt;</span><br><span class="line">&lt;/dependencyManagement&gt;</span><br></pre></td></tr></table></figure>

<p>上面是dependencyManagement依赖管理，相当于以后在dependencies里引spring cloud alibaba就不用写版本号。注意他和普通依赖的区别，他只是备注一下，并没有加入依赖</p>
<h2 id="三、Nacos注册中心"><a href="#三、Nacos注册中心" class="headerlink" title="三、Nacos注册中心"></a>三、Nacos注册中心</h2><h4 id="1、安装启动nacos："><a href="#1、安装启动nacos：" class="headerlink" title="1、安装启动nacos："></a>1、安装启动nacos：</h4><p>下载–解压–双击bin/startup.cmd。<a target="_blank" rel="noopener" href="http://127.0.0.1:8848/nacos/">http://127.0.0.1:8848/nacos/</a> 账号密码nacos<br>Linux/Unix/Mac 操作系统，执行命令 <code>sh startup.sh -m standalone</code></p>
<h4 id="2、nacos使用："><a href="#2、nacos使用：" class="headerlink" title="2、nacos使用："></a>2、nacos使用：</h4><ol start="3">
<li><p>依赖：放到common里，不写版本是因为父项目或spring-cloud里面有了版本管理</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&lt;dependency&gt;</span><br><span class="line">    &lt;groupId&gt;com.alibaba.cloud&lt;/groupId&gt;</span><br><span class="line">    &lt;artifactId&gt;spring-cloud-starter-alibaba-nacos-discovery&lt;/artifactId&gt;</span><br><span class="line">&lt;/dependency&gt;</span><br></pre></td></tr></table></figure></li>
<li><p>开启服务注册与发现功能<br>使用 <code>@EnableDiscoveryClient</code> </p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@SpringBootApplication</span></span><br><span class="line"><span class="meta">@EnableDiscoveryClient</span> <span class="comment">// </span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">ProviderApplication</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        SpringApplication.run(Application.class, args);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="meta">@RestController</span></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">EchoController</span> </span>&#123;</span><br><span class="line">        <span class="meta">@GetMapping(value = &quot;/echo/&#123;string&#125;&quot;)</span></span><br><span class="line">        <span class="function"><span class="keyword">public</span> String <span class="title">echo</span><span class="params">(<span class="meta">@PathVariable</span> String string)</span> </span>&#123;</span><br><span class="line">            <span class="keyword">return</span> string;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li><p>最后application.yml内容，指定nacos的地址，配置服务中心名和当前模块名字</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">datasource:</span></span><br><span class="line">    <span class="attr">username:</span> <span class="string">root</span></span><br><span class="line">    <span class="attr">password:</span> <span class="string">root</span></span><br><span class="line">    <span class="attr">url:</span> <span class="string">jdbc:mysql://192.168.56.10:3306/gulimall-sms?useUnicode=true&amp;characterEncoding=UTF-8&amp;useSSL=false&amp;serverTimezone=Asia/Shanghai</span></span><br><span class="line">    <span class="attr">driver-class-name:</span> <span class="string">com.mysql.cj.jdbc.Driver</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">nacos:</span></span><br><span class="line">      <span class="attr">discovery:</span></span><br><span class="line">        <span class="attr">server-addr:</span> <span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span><span class="string">:8848//1、指定nacos的地址</span></span><br><span class="line">  <span class="attr">application:</span></span><br><span class="line">    <span class="attr">name:</span> <span class="string">gulimall-coupon</span> <span class="string">//2、向nacos中命名applicatin.name</span>       </span><br><span class="line"><span class="attr">mybatis-plus:</span></span><br><span class="line">  <span class="attr">mapper-locations:</span> <span class="string">classpath:/mapper/**/*.xml</span></span><br><span class="line">  <span class="attr">global-config:</span></span><br><span class="line">    <span class="attr">db-config:</span></span><br><span class="line">      <span class="attr">id-type:</span> <span class="string">auto</span></span><br><span class="line">      <span class="attr">logic-delete-value:</span> <span class="number">1</span></span><br><span class="line">      <span class="attr">logic-not-delete-value:</span> <span class="number">0</span>          </span><br><span class="line"><span class="attr">server:</span></span><br><span class="line">  <span class="attr">port:</span> <span class="number">7000</span></span><br></pre></td></tr></table></figure></li>
</ol>
<p>依次给member、配置上面的yaml，改下name就行。再给每个项目配置类上加上注解@EnableDiscoveryClient</p>
<h4 id="3、nacos测试："><a href="#3、nacos测试：" class="headerlink" title="3、nacos测试："></a>3、nacos测试：</h4><p>测试member和coupon的远程调用</p>
<ol start="2">
<li>想要获取当前会员领取到的所有优惠券。先去注册中心找优惠券服务，注册中心调一台优惠券服务器给会员，会员服务器发送请求给这台优惠券服务器，然后对方响应。</li>
<li>服务请求方发送了2次请求，先问nacos要地址，然后再请求</li>
</ol>
<h2 id="四、Feign远程调用"><a href="#四、Feign远程调用" class="headerlink" title="四、Feign远程调用"></a>四、Feign远程调用</h2><ol>
<li>声明式远程调用</li>
<li>feign是一个声明式的HTTP客户端，他的目的就是让远程调用更加简单。给远程服务发的是HTTP请求。</li>
<li>会员服务想要远程调用优惠券服务，只需要给会员服务里引入openfeign依赖，他就有了远程调用其他服务的能力</li>
</ol>
<h3 id="（—）、优惠券coupon部分"><a href="#（—）、优惠券coupon部分" class="headerlink" title="（—）、优惠券coupon部分"></a>（—）、优惠券coupon部分</h3><h4 id="1、pom-xml"><a href="#1、pom-xml" class="headerlink" title="1、pom.xml"></a>1、pom.xml</h4><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.cloud<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-cloud-starter-openfeign<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span>                  </span><br></pre></td></tr></table></figure>

<p>我们之前在member的pom.xml已经引用过了（微服务）。</p>
<h4 id="2、控制层"><a href="#2、控制层" class="headerlink" title="2、控制层"></a>2、控制层</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@RequestMapping(&quot;coupon/coupon&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">CouponController</span> </span>&#123;</span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> CouponService couponService;</span><br><span class="line">    <span class="meta">@RequestMapping(&quot;/member/list&quot;)</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> R <span class="title">membercoupons</span><span class="params">()</span></span>&#123;    <span class="comment">//全系统的所有返回都返回R</span></span><br><span class="line">        <span class="comment">// 应该去数据库查用户对于的优惠券，但这个我们简化了，不去数据库查了，构造了一个优惠券给他返回</span></span><br><span class="line">        CouponEntity couponEntity = <span class="keyword">new</span> CouponEntity();</span><br><span class="line">        couponEntity.setCouponName(<span class="string">&quot;满100-10&quot;</span>);<span class="comment">//优惠券的名字</span></span><br><span class="line">        <span class="keyword">return</span> R.ok().put(<span class="string">&quot;coupons&quot;</span>,Arrays.asList(couponEntity));</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<h3 id="（二）、会员member部分内容"><a href="#（二）、会员member部分内容" class="headerlink" title="（二）、会员member部分内容"></a>（二）、会员member部分内容</h3><h4 id="1、配置类"><a href="#1、配置类" class="headerlink" title="1、配置类"></a>1、配置类</h4><p>加注解<code>@EnableDiscoveryClient，</code>告诉member是一个远程调用客户端，member是要调用东西的</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">* 想要远程调用的步骤：</span></span><br><span class="line"><span class="comment">* 1 引入openfeign</span></span><br><span class="line"><span class="comment">* 2 编写一个接口，接口告诉springcloud这个接口需要调用远程服务</span></span><br><span class="line"><span class="comment">* 	2.1 在接口里声明@FeignClient(&quot;gulimall-coupon&quot;)他是一个远程调用客户端且要调用coupon服务</span></span><br><span class="line"><span class="comment">* 	2.2 要调用coupon服务的/coupon/coupon/member/list方法</span></span><br><span class="line"><span class="comment">* 3 开启远程调用功能 @EnableFeignClients，要指定远程调用功能放的基础包</span></span><br><span class="line"><span class="comment">* */</span></span><br><span class="line"><span class="meta">@EnableFeignClients(basePackages=&quot;com.atguigu.gulimall.member.feign&quot;)</span><span class="comment">//扫描接口方法注解</span></span><br><span class="line"><span class="meta">@EnableDiscoveryClient</span><span class="comment">// 注册到nacos</span></span><br><span class="line"><span class="meta">@SpringBootApplication</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">gulimallMemberApplication</span> </span>&#123;</span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">		SpringApplication.run(gulimallMemberApplication.class, args);</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="2、新建类："><a href="#2、新建类：" class="headerlink" title="2、新建类："></a>2、新建类：</h4><p>要调用什么东西呢？就是我们刚才写的优惠券的功能，复制函数部分，在member的com.atguigu.gulimall.member.feign包下</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@FeignClient(&quot;gulimall-coupon&quot;)</span> <span class="comment">//告诉spring cloud这个接口是一个远程客户端，要调用coupon服务(nacos中找到)</span></span><br><span class="line"><span class="comment">//具体是调用coupon服务的/coupon/coupon/member/list对应的方法</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">interface</span> <span class="title">CouponFeignService</span> </span>&#123;</span><br><span class="line">    <span class="comment">// 远程服务的url</span></span><br><span class="line">    <span class="comment">//注意写全优惠券类上还有映射//注意我们这个地方不是控制层，所以这个请求映射请求的不是我们服务器上的东西，而是nacos注册中心的</span></span><br><span class="line">    <span class="meta">@RequestMapping(&quot;/coupon/coupon/member/list&quot;)</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> R <span class="title">membercoupons</span><span class="params">()</span></span>;<span class="comment">//得到一个R对象</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>@FeignClient+@RequestMapping构成远程调用的坐标</p>
<p>其他类中看似只是调用了CouponFeignService.membercoupons()，而实际上该方法跑去nacos里和rpc里调用了才拿到东西返回</p>
</blockquote>
<h4 id="3、测试请求"><a href="#3、测试请求" class="headerlink" title="3、测试请求"></a>3、测试请求</h4><p>控制层写一个测试请求</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@RestController</span></span><br><span class="line"><span class="meta">@RequestMapping(&quot;member/member&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MemberController</span> </span>&#123;</span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> MemberService memberService;</span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    CouponFeignService couponFeignService;</span><br><span class="line">    <span class="meta">@RequestMapping(&quot;/coupons&quot;)</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> R <span class="title">test</span><span class="params">()</span></span>&#123;</span><br><span class="line">        MemberEntity memberEntity = <span class="keyword">new</span> MemberEntity();</span><br><span class="line">        memberEntity.setNickname(<span class="string">&quot;会员昵称张三&quot;</span>);</span><br><span class="line">        R membercoupons = couponFeignService.membercoupons();<span class="comment">//假设张三去数据库查了后返回了张三的优惠券信息</span></span><br><span class="line">        <span class="comment">//打印会员和优惠券信息</span></span><br><span class="line">        <span class="keyword">return</span> R.ok().put(<span class="string">&quot;member&quot;</span>,memberEntity).put(<span class="string">&quot;coupons&quot;</span>,membercoupons.get(<span class="string">&quot;coupons&quot;</span>));</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<h4 id="4、测试："><a href="#4、测试：" class="headerlink" title="4、测试："></a>4、测试：</h4><p>htttp://localhost:8000/member/member/coupons</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">    <span class="string">&quot;msg&quot;</span>:<span class="string">&quot;success&quot;</span>,</span><br><span class="line">    <span class="string">&quot;code&quot;</span>:<span class="number">0</span>,</span><br><span class="line">    <span class="string">&quot;coupons&quot;</span>:[</span><br><span class="line">        &#123;<span class="string">&quot;id&quot;</span>:<span class="keyword">null</span>,<span class="string">&quot;couponType&quot;</span>:<span class="keyword">null</span>,<span class="string">&quot;couponImg&quot;</span>:<span class="keyword">null</span>,</span><br><span class="line">         <span class="string">&quot;couponName&quot;</span>:<span class="string">&quot;满100-10&quot;</span>,<span class="string">&quot;num&quot;</span>:<span class="keyword">null</span>,<span class="string">&quot;amount&quot;</span>:<span class="keyword">null</span>,<span class="string">&quot;perLimit&quot;</span>:<span class="keyword">null</span>,</span><br><span class="line">         <span class="string">&quot;minPoint&quot;</span>:<span class="keyword">null</span>,<span class="string">&quot;startTime&quot;</span>:<span class="keyword">null</span>,<span class="string">&quot;endTime&quot;</span>:<span class="keyword">null</span>,<span class="string">&quot;useType&quot;</span>:<span class="keyword">null</span>,</span><br><span class="line">         <span class="string">&quot;note&quot;</span>:<span class="keyword">null</span>,<span class="string">&quot;publishCount&quot;</span>:<span class="keyword">null</span>,<span class="string">&quot;useCount&quot;</span>:<span class="keyword">null</span>,<span class="string">&quot;receiveCount&quot;</span>:<span class="keyword">null</span>,</span><br><span class="line">         <span class="string">&quot;enableStartTime&quot;</span>:<span class="keyword">null</span>,<span class="string">&quot;enableEndTime&quot;</span>:<span class="keyword">null</span>,<span class="string">&quot;code&quot;</span>:<span class="keyword">null</span>,</span><br><span class="line">         <span class="string">&quot;memberLevel&quot;</span>:<span class="keyword">null</span>,<span class="string">&quot;publish&quot;</span>:<span class="keyword">null</span>&#125;</span><br><span class="line">    ],</span><br><span class="line">    <span class="string">&quot;member&quot;</span>:&#123;<span class="string">&quot;id&quot;</span>:<span class="keyword">null</span>,<span class="string">&quot;levelId&quot;</span>:<span class="keyword">null</span>,<span class="string">&quot;username&quot;</span>:<span class="keyword">null</span>,<span class="string">&quot;password&quot;</span>:<span class="keyword">null</span>,</span><br><span class="line">              <span class="string">&quot;nickname&quot;</span>:<span class="string">&quot;会员昵称张三&quot;</span>,<span class="string">&quot;mobile&quot;</span>:<span class="keyword">null</span>,<span class="string">&quot;email&quot;</span>:<span class="keyword">null</span>,</span><br><span class="line">              <span class="string">&quot;header&quot;</span>:<span class="keyword">null</span>,<span class="string">&quot;gender&quot;</span>:<span class="keyword">null</span>,<span class="string">&quot;birth&quot;</span>:<span class="keyword">null</span>,</span><br><span class="line">              <span class="string">&quot;city&quot;</span>:<span class="keyword">null</span>,<span class="string">&quot;job&quot;</span>:<span class="keyword">null</span>,<span class="string">&quot;sign&quot;</span>:<span class="keyword">null</span>,<span class="string">&quot;sourceType&quot;</span>:<span class="keyword">null</span>,</span><br><span class="line">              <span class="string">&quot;integration&quot;</span>:<span class="keyword">null</span>,<span class="string">&quot;growth&quot;</span>:<span class="keyword">null</span>,<span class="string">&quot;status&quot;</span>:<span class="keyword">null</span>,<span class="string">&quot;createTime&quot;</span>:<span class="keyword">null</span>&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>coupon里的R.ok()是什么，就是设置了个msg</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">R</span> <span class="keyword">extends</span> <span class="title">HashMap</span>&lt;<span class="title">String</span>, <span class="title">Object</span>&gt; </span>&#123;<span class="comment">//R继承了HashMap</span></span><br><span class="line">    <span class="comment">// ok是个静态方法，new了一个R对象，并且</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> R <span class="title">ok</span><span class="params">(String msg)</span> </span>&#123;</span><br><span class="line">        R r = <span class="keyword">new</span> R();</span><br><span class="line">        r.put(<span class="string">&quot;msg&quot;</span>, msg);<span class="comment">//调用了super.put(key, value);，即hashmap的put</span></span><br><span class="line">        <span class="keyword">return</span> r;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="五、nacos配置中心"><a href="#五、nacos配置中心" class="headerlink" title="五、nacos配置中心"></a>五、nacos配置中心</h2><h3 id="1、nacos作为配置中心。"><a href="#1、nacos作为配置中心。" class="headerlink" title="1、nacos作为配置中心。"></a>1、nacos作为配置中心。</h3><p>不在application.properties等文件中配置了，而是放到nacos配置中心公用，无需每台机器都改。</p>
<p>1、添加 nacos配置中心依赖<br>在common中添加</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.alibaba.cloud<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-cloud-starter-alibaba-nacos-config<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>2、coupons中创建配置文件bootstrap.properties<br>项目创建/src/main/resources/bootstrap.properties ，这文件是springboot里规定的，优先级别application.properties高</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"># 改名字，对应nacos里的配置文件名</span><br><span class="line">spring.application.name=gulimall-coupon</span><br><span class="line">spring.cloud.nacos.config.server-addr=127.0.0.1:8848</span><br></pre></td></tr></table></figure>

<p>3、加上@Value注解使用</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@RestController</span></span><br><span class="line"><span class="meta">@RequestMapping(&quot;coupon/coupon&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">CouponController</span> </span>&#123;</span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> CouponService couponService;</span><br><span class="line">    <span class="meta">@Value(&quot;$&#123;coupon.user.name&#125;&quot;)</span><span class="comment">//从application.properties中获取//不要写user.name，他是环境里的变量</span></span><br><span class="line">    <span class="keyword">private</span> String name;</span><br><span class="line">    <span class="meta">@Value(&quot;$&#123;coupon.user.age&#125;&quot;)</span></span><br><span class="line">    <span class="keyword">private</span> Integer age;</span><br><span class="line">    <span class="meta">@RequestMapping(&quot;/test&quot;)</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> R <span class="title">test</span><span class="params">()</span></span>&#123;</span><br><span class="line">        <span class="keyword">return</span> R.ok().put(<span class="string">&quot;name&quot;</span>,name).put(<span class="string">&quot;age&quot;</span>,age);</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<p>4、浏览器去nacos里的配置列表，点击＋号，data ID：<code>gulimall-coupon.properties</code>，配置</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"># gulimall-coupon.properties</span><br><span class="line">coupon.user.name=<span class="string">&quot;配置中心&quot;</span>      </span><br><span class="line">coupon.user.age=<span class="number">12</span></span><br></pre></td></tr></table></figure>

<p>5、然后点击发布。重启coupon（生产中加入@RefreshScope即可），<a target="_blank" rel="noopener" href="http://localhost:7000/coupon/coupon/test">http://localhost:7000/coupon/coupon/test</a></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&#123;<span class="string">&quot;msg&quot;</span>:<span class="string">&quot;success&quot;</span>,<span class="string">&quot;code&quot;</span>:<span class="number">0</span>,<span class="string">&quot;name&quot;</span>:<span class="string">&quot;配置中心&quot;</span>,<span class="string">&quot;age&quot;</span>:<span class="number">12</span>&#125;</span><br></pre></td></tr></table></figure>

<p>实际生产中不能重启应用。在coupon的控制层上加<code>@RefreshScope</code></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@RefreshScope</span></span><br><span class="line"><span class="meta">@RestController</span></span><br><span class="line"><span class="meta">@RequestMapping(&quot;coupon/coupon&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">CouponController</span> </span>&#123;</span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> CouponService couponService;</span><br><span class="line">    <span class="meta">@Value(&quot;$&#123;coupon.user.name&#125;&quot;)</span><span class="comment">//从application.properties中获取//不要写user.name，他是环境里的变量</span></span><br><span class="line">    <span class="keyword">private</span> String name;</span><br><span class="line">    <span class="meta">@Value(&quot;$&#123;coupon.user.age&#125;&quot;)</span></span><br><span class="line">    <span class="keyword">private</span> Integer age;   </span><br><span class="line">    <span class="meta">@RequestMapping(&quot;/test&quot;)</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> R <span class="title">test</span><span class="params">()</span></span>&#123;</span><br><span class="line">        <span class="keyword">return</span> R.ok().put(<span class="string">&quot;name&quot;</span>,name).put(<span class="string">&quot;age&quot;</span>,age);</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<p>重启后(让注解生效)，在nacos浏览器里修改配置，修改就可以观察到能动态修改了<br>nacos的配置内容优先于项目本地的配置内容。</p>
<h3 id="2、配置中心进阶"><a href="#2、配置中心进阶" class="headerlink" title="2、配置中心进阶"></a>2、<strong>配置中心进阶</strong></h3><p>在nacos浏览器中还可以配置：<br>1、命名空间：用作配置隔离。（一般每个微服务一个命名空间）<br>默认public。默认新增的配置都在public空间下<br>开发、测试、开发可以用命名空间分割。properties每个空间有一份。也可以为每个微服务配置一个命名空间，微服务互相隔离</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"># 可以选择对应的命名空间，写上对应环境的命名空间ID</span><br><span class="line">spring.cloud.nacos.config.namespace=b176a68a-6800-4648-833b-be10be8bab00</span><br></pre></td></tr></table></figure>

<p>2、配置集：一组相关或不相关配置项的集合。<br>3、配置集ID：类似于配置文件名，即Data ID<br>4、配置分组：默认所有的配置集都属于<code>DEFAULT_GROUP</code>。双十一，618的优惠策略改分组即可</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"># 更改配置分组</span><br><span class="line">spring.cloud.nacos.config.group=DEFAULT_GROUP</span><br></pre></td></tr></table></figure>

<p>最终方案：每个微服务创建自己的命名空间，然后使用配置分组区分环境（dev/test/prod）</p>
<p>3、<strong>加载多配置集</strong></p>
<p>把原来application.yml的内容抽出去。在nacos里创建好，在coupons里指定要导入的配置。<br>1、bootstrap.properties<br>用数组<code>spring.cloud.nacos.config.extension-configs[]</code>写明每个配置集</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line">spring.application.name=gulimall-coupon</span><br><span class="line">spring.cloud.nacos.config.server-addr=127.0.0.1:8848</span><br><span class="line"># 可以选择对应的命名空间 ，写上对应环境的命名空间ID</span><br><span class="line">spring.cloud.nacos.config.namespace=b176a68a-6800-4648-833b  </span><br><span class="line"># 更改配置分组</span><br><span class="line">spring.cloud.nacos.config.group=dev</span><br><span class="line"></span><br><span class="line">#新版本不建议用下面的了</span><br><span class="line">#spring.cloud.nacos.config.ext-config[0].data-id=datasource.yml</span><br><span class="line">#spring.cloud.nacos.config.ext-config[0].group=dev</span><br><span class="line">#spring.cloud.nacos.config.ext-config[0].refresh=true</span><br><span class="line">#spring.cloud.nacos.config.ext-config[1].data-id=mybatis.yml</span><br><span class="line">#spring.cloud.nacos.config.ext-config[1].group=dev</span><br><span class="line">#spring.cloud.nacos.config.ext-config[1].refresh=true</span><br><span class="line">#spring.cloud.nacos.config.ext-config[2].data-id=other.yml</span><br><span class="line">#spring.cloud.nacos.config.ext-config[2].group=dev</span><br><span class="line">#spring.cloud.nacos.config.ext-config[2].refresh=true</span><br><span class="line"></span><br><span class="line">spring.cloud.nacos.config.extension-configs[0].data-id=datasource.yml</span><br><span class="line">spring.cloud.nacos.config.extension-configs[0].group=dev</span><br><span class="line">spring.cloud.nacos.config.extension-configs[0].refresh=true</span><br><span class="line"></span><br><span class="line">spring.cloud.nacos.config.extension-configs[1].data-id=mybatis.yml</span><br><span class="line">spring.cloud.nacos.config.extension-configs[1].group=dev</span><br><span class="line">spring.cloud.nacos.config.extension-configs[1].refresh=true</span><br><span class="line"></span><br><span class="line">spring.cloud.nacos.config.extension-configs[2].data-id=other.yml</span><br><span class="line">spring.cloud.nacos.config.extension-configs[2].group=dev</span><br><span class="line">spring.cloud.nacos.config.extension-configs[2].refresh=true</span><br></pre></td></tr></table></figure>

<h2 id="六、网关gateway-88"><a href="#六、网关gateway-88" class="headerlink" title="六、网关gateway-88"></a>六、网关gateway-88</h2><h3 id="1、作用"><a href="#1、作用" class="headerlink" title="1、作用"></a>1、作用</h3><p>1、动态上下线：发送请求需知道商品服务的地址，如果商品服务器有123服务器，<strong>1号掉线后</strong>，还得改，需要网关动态地管理，能从注册中心中实时地感知某个服务上线还是下线。【先通过网关，网关路由到服务提供者】<br>2、拦截：请求也要加上询问权限，看用户有没有权限访问这个请求，也需要网关。<br>3、网关是请求流量的入口，常用功能包括路由转发，权限校验，限流控制等。</p>
<h3 id="2、三大核心概念："><a href="#2、三大核心概念：" class="headerlink" title="2、三大核心概念："></a>2、三大核心概念：</h3><p>1、Predicate断言: .就是java里的断言函数，匹配请求里的任何信息，包括请求头等。根据请求头路由哪个服务<br>2、Route路由: .发一个请求给网关，网关要将请求路由到指定的服务。路由有id，目的地uri，断言的集合，匹配了断言就能到指定位置<br>3、Filter过滤器: .过滤器请求和响应都可以被修改。</p>
<h3 id="3、总概览"><a href="#3、总概览" class="headerlink" title="3、总概览"></a>3、总概览</h3><p>客户端发请求给服务端。中间有网关。先交给映射器，如果能处理就交给handler处理，然后交给一系列filer，然后给指定的服务，再返回回来给客户端。<br>1、断言：只有断言成功了，才路由到指定的地址。</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">gateway:</span></span><br><span class="line">      <span class="attr">routes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">after_route</span></span><br><span class="line">        <span class="attr">uri:</span> <span class="string">https://example.org</span></span><br><span class="line">        <span class="attr">predicates:</span></span><br><span class="line">        <span class="bullet">-</span> <span class="string">Cookie=mycookie,mycookievalue</span></span><br></pre></td></tr></table></figure>

<p><code>-</code>代表数组，可以设置Cookie等内容。</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">gateway:</span></span><br><span class="line">      <span class="attr">routes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">after_route</span></span><br><span class="line">        <span class="attr">uri:</span> <span class="string">https://example.org</span></span><br><span class="line">        <span class="attr">predicates:</span></span><br><span class="line">        <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Cookie</span></span><br><span class="line">          <span class="attr">args:</span></span><br><span class="line">            <span class="attr">name:</span> <span class="string">mycookie</span></span><br><span class="line">            <span class="attr">regexp:</span> <span class="string">mycookievalue</span></span><br></pre></td></tr></table></figure>

<h6 id="1、配置nacos注册中心"><a href="#1、配置nacos注册中心" class="headerlink" title="1、配置nacos注册中心"></a>1、配置nacos注册中心</h6><p>在gateway服务中开启注册服务发现<code>@EnableDiscoveryClient</code>，配置nacos注册中心地址applicaion.properties。这样gateway也注册到了nacos中，其他服务就能找到nacos，网关也能通过nacos找到其他服务</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848</span><br><span class="line">spring.application.name=gulimall-gateway</span><br><span class="line">server.port=88</span><br></pre></td></tr></table></figure>

<h6 id="2、配置nacos配置中心地址"><a href="#2、配置nacos配置中心地址" class="headerlink" title="2、配置nacos配置中心地址"></a>2、配置nacos配置中心地址</h6><p>1、bootstrap.properties 填写nacos配置中心地址</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">spring.application.name=gulimall-gateway</span><br><span class="line">spring.cloud.nacos.config.server-addr=127.0.0.1:8848</span><br><span class="line">spring.cloud.nacos.config.namespace=bfa85f10-1a9a-460c-a7dc-efa961b45cc1</span><br></pre></td></tr></table></figure>

<p>2、本项目在nacos中的服务名</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">    <span class="attr">application:</span></span><br><span class="line">        <span class="attr">name:</span> <span class="string">gulimall-gateway</span></span><br></pre></td></tr></table></figure>

<p>3、去nacos里创建命名空间gateway（项目与项目用命名空间隔离），然后在命名空间里创建文件guilmall-gateway.yml</p>
<p>在项目里创建application.yml，根据条件转发到uri等</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">gateway:</span></span><br><span class="line">      <span class="attr">routes:</span></span><br><span class="line">        <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">test_route</span></span><br><span class="line">          <span class="attr">uri:</span> <span class="string">https://www.baidu.com</span></span><br><span class="line">          <span class="attr">predicates:</span></span><br><span class="line">            <span class="bullet">-</span> <span class="string">Query=url,baidu</span></span><br><span class="line"></span><br><span class="line">        <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">qq_route</span></span><br><span class="line">          <span class="attr">uri:</span> <span class="string">https://www.qq.com</span></span><br><span class="line">          <span class="attr">predicates:</span></span><br><span class="line">            <span class="bullet">-</span> <span class="string">Query=url,qq</span></span><br><span class="line"></span><br><span class="line">        <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">product_route</span></span><br><span class="line">          <span class="attr">uri:</span> <span class="string">lb://gulimall-product</span></span><br><span class="line">          <span class="attr">predicates:</span></span><br><span class="line">            <span class="bullet">-</span> <span class="string">Path=/api/product/**</span></span><br><span class="line">          <span class="attr">filters:</span></span><br><span class="line">            <span class="bullet">-</span> <span class="string">RewritePath=/api/(?&lt;segment&gt;.*),/$\&#123;segment&#125;</span></span><br><span class="line"></span><br><span class="line">        <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">third_party_route</span></span><br><span class="line">          <span class="attr">uri:</span> <span class="string">lb://gulimall-third-party</span></span><br><span class="line">          <span class="attr">predicates:</span></span><br><span class="line">            <span class="bullet">-</span> <span class="string">Path=/api/thirdparty/**</span></span><br><span class="line">          <span class="attr">filters:</span></span><br><span class="line">            <span class="bullet">-</span> <span class="string">RewritePath=/api/thirdparty/(?&lt;segment&gt;.*),/$\&#123;segment&#125;</span></span><br><span class="line"></span><br><span class="line">        <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">member_route</span></span><br><span class="line">          <span class="attr">uri:</span> <span class="string">lb://gulimall-member</span></span><br><span class="line">          <span class="attr">predicates:</span></span><br><span class="line">            <span class="bullet">-</span> <span class="string">Path=/api/member/**</span></span><br><span class="line">          <span class="attr">filters:</span></span><br><span class="line">            <span class="bullet">-</span> <span class="string">RewritePath=/api/(?&lt;segment&gt;.*),/$\&#123;segment&#125;</span></span><br><span class="line"></span><br><span class="line">        <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">ware_route</span></span><br><span class="line">          <span class="attr">uri:</span> <span class="string">lb://gulimall-ware</span></span><br><span class="line">          <span class="attr">predicates:</span></span><br><span class="line">            <span class="bullet">-</span> <span class="string">Path=/api/ware/**</span></span><br><span class="line">          <span class="attr">filters:</span></span><br><span class="line">            <span class="bullet">-</span> <span class="string">RewritePath=/api/(?&lt;segment&gt;.*),/$\&#123;segment&#125;</span></span><br><span class="line"></span><br><span class="line">        <span class="bullet">-</span> <span class="attr">id:</span> <span class="string">admin_route</span></span><br><span class="line">          <span class="attr">uri:</span> <span class="string">lb://renren-fast</span></span><br><span class="line">          <span class="attr">predicates:</span></span><br><span class="line">            <span class="bullet">-</span> <span class="string">Path=/api/**</span></span><br><span class="line">          <span class="attr">filters:</span>  <span class="comment"># 这段过滤器和验证码有关，api内容缓存了/renren-fast，还得注意/renren-fast也注册到nacos中</span></span><br><span class="line">            <span class="bullet">-</span> <span class="string">RewritePath=/api/(?&lt;segment&gt;.*),/renren-fast/$\&#123;segment&#125;</span></span><br><span class="line"><span class="comment">## 前端项目，/api前缀。开来到网关后断言先匹配到，过滤器修改url，比如跳转到renren微服务，所以要注意renren后端项目也注册到 nacos里</span></span><br><span class="line"><span class="comment">## http://localhost:88/api/captcha.jpg   http://localhost:8080/renren-fast/captcha.jpg</span></span><br><span class="line"><span class="comment">## http://localhost:88/api/product/category/list/tree http://localhost:10000/product/category/list/tree</span></span><br></pre></td></tr></table></figure>

<h2 id="七、三级分类"><a href="#七、三级分类" class="headerlink" title="七、三级分类"></a>七、三级分类</h2><h4 id="1、启动项目环境"><a href="#1、启动项目环境" class="headerlink" title="1、启动项目环境"></a>1、启动项目环境</h4><p>最起码得启动renren-fast、nacos、gateway、product</p>
<h4 id="2、element-ui的使用"><a href="#2、element-ui的使用" class="headerlink" title="2、element-ui的使用"></a>2、element-ui的使用</h4><p>提供了tree组件，他的数据是以data属性显示的。而他的子菜单是由data里的children属性决定的，当然这个属性可以改</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">defaultProps: &#123;</span><br><span class="line">    children: <span class="string">&quot;children&quot;</span>,</span><br><span class="line">    label: <span class="string">&quot;name&quot;</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="3、pms-category（商品的分类）为例说明"><a href="#3、pms-category（商品的分类）为例说明" class="headerlink" title="3、pms_category（商品的分类）为例说明"></a>3、pms_category（商品的分类）为例说明</h4><h5 id="1、数据库搭建"><a href="#1、数据库搭建" class="headerlink" title="1、数据库搭建"></a>1、数据库搭建</h5><p>SQL语言</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> DATABASE <span class="comment">/*!32312 IF NOT EXISTS*/</span>`gulimall_pms` <span class="comment">/*!40100 DEFAULT CHARACTER SET utf8mb4 */</span>;</span><br><span class="line"></span><br><span class="line">USE `gulimall_pms`;</span><br><span class="line"></span><br><span class="line"><span class="keyword">SET</span> FOREIGN_KEY_CHES<span class="operator">=</span><span class="number">0</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">DROP</span> <span class="keyword">TABLE</span> IF <span class="keyword">EXISTS</span> `pms_category`;</span><br><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> `pms_category`  (</span><br><span class="line">    `cat_id` <span class="type">bigint</span>(<span class="number">20</span>) <span class="keyword">NOT</span> <span class="keyword">NULL</span> AUTO_INCREMENT COMMENT <span class="string">&#x27;分类id&#x27;</span>,</span><br><span class="line">    `name` <span class="type">char</span>(<span class="number">50</span>) <span class="type">CHARACTER</span> <span class="keyword">SET</span> utf8mb4 <span class="keyword">COLLATE</span> utf8mb4_general_ci <span class="keyword">NULL</span> <span class="keyword">DEFAULT</span> <span class="keyword">NULL</span> COMMENT <span class="string">&#x27;分类名称&#x27;</span>,</span><br><span class="line">    `parent_cid` <span class="type">bigint</span>(<span class="number">20</span>) <span class="keyword">NULL</span> <span class="keyword">DEFAULT</span> <span class="keyword">NULL</span> COMMENT <span class="string">&#x27;父分类id&#x27;</span>,</span><br><span class="line">    `cat_level` <span class="type">int</span>(<span class="number">11</span>) <span class="keyword">NULL</span> <span class="keyword">DEFAULT</span> <span class="keyword">NULL</span> COMMENT <span class="string">&#x27;层级&#x27;</span>,</span><br><span class="line">    `show_status` tinyint(<span class="number">4</span>) <span class="keyword">NULL</span> <span class="keyword">DEFAULT</span> <span class="keyword">NULL</span> COMMENT <span class="string">&#x27;是否显示[0-不显示，1显示]&#x27;</span>,</span><br><span class="line">    `sort` <span class="type">int</span>(<span class="number">11</span>) <span class="keyword">NULL</span> <span class="keyword">DEFAULT</span> <span class="keyword">NULL</span> COMMENT <span class="string">&#x27;排序&#x27;</span>,</span><br><span class="line">    `icon` <span class="type">char</span>(<span class="number">255</span>) <span class="type">CHARACTER</span> <span class="keyword">SET</span> utf8mb4 <span class="keyword">COLLATE</span> utf8mb4_general_ci <span class="keyword">NULL</span> <span class="keyword">DEFAULT</span> <span class="keyword">NULL</span> COMMENT <span class="string">&#x27;图标地址&#x27;</span>,</span><br><span class="line">    `product_unit` <span class="type">char</span>(<span class="number">50</span>) <span class="type">CHARACTER</span> <span class="keyword">SET</span> utf8mb4 <span class="keyword">COLLATE</span> utf8mb4_general_ci <span class="keyword">NULL</span> <span class="keyword">DEFAULT</span> <span class="keyword">NULL</span> COMMENT <span class="string">&#x27;计量单位&#x27;</span>,</span><br><span class="line">    `product_count` <span class="type">int</span>(<span class="number">11</span>) <span class="keyword">NULL</span> <span class="keyword">DEFAULT</span> <span class="keyword">NULL</span> COMMENT <span class="string">&#x27;商品数量&#x27;</span>,</span><br><span class="line">    <span class="keyword">PRIMARY</span> KEY (`cat_id`) <span class="keyword">USING</span> BTREE, </span><br><span class="line">    INDEX `parent_cid`(`parent_cid`) <span class="keyword">USING</span> BTREE</span><br><span class="line">) ENGINE <span class="operator">=</span> InnoDB AUTO_INCREMENT <span class="operator">=</span> <span class="number">1437</span> <span class="type">CHARACTER</span> <span class="keyword">SET</span> <span class="operator">=</span> utf8mb4 <span class="keyword">COLLATE</span> <span class="operator">=</span> utf8mb4_general_ci COMMENT <span class="operator">=</span> <span class="string">&#x27;商品三级分类&#x27;</span> ROW_FORMAT <span class="operator">=</span> <span class="keyword">Dynamic</span>;</span><br></pre></td></tr></table></figure>

<p>属性：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">cat_id：分类id，cat代表分类，<span class="type">bigint</span>(<span class="number">20</span>)</span><br><span class="line">name：分类名称</span><br><span class="line">parent_cid：在哪个父目录下</span><br><span class="line">cat_level：分类层级</span><br><span class="line">show_status：是否显示，用于逻辑删除</span><br><span class="line">sort：同层级同父目录下显示顺序</span><br><span class="line">ico图标，product_unit商品计量单位，</span><br><span class="line">InnoDB表，自增大小<span class="number">1437</span>，utf编码，动态行格式</span><br></pre></td></tr></table></figure>

<h4 id="4、接着操作后台"><a href="#4、接着操作后台" class="headerlink" title="4、接着操作后台"></a>4、接着操作后台</h4><p>1、localhost:8001 ， 点击系统管理，菜单管理，新增<br>目录<br><strong>商品系统</strong><br>一级菜单<br><img src="https://img-blog.csdnimg.cn/img_convert/213151d71e4ab7fb0bd288898b82b4c0.png" alt="img" style="zoom:50%;" /></p>
<p>左侧多了商品系统，这个菜单添加到了<code>guli-admin.sys_menu</code>表里(memu_id=31 parent_id=0 name=商品系统 icon=editor )/</p>
<p>2、继续新增<br>菜单<br><strong>分类维护</strong><br>商品系统<br>product/category<br>…<br>menu<br><img src="https://img-blog.csdnimg.cn/img_convert/2e2927a8bd8d8cb964e276627b17b0fa.png" alt="img" style="zoom:50%;" /></p>
<p><code>guli-admin.sys_menu</code>表又多了一行，父id是刚才的商品系统id</p>
<h5 id="菜单路由"><a href="#菜单路由" class="headerlink" title="菜单路由"></a>菜单路由</h5><p>在左侧点击【商品系统-分类维护】，希望在此展示3级分类。可以看到</p>
<ul>
<li>url是<code>http://localhost:8001/#/product-category</code></li>
<li>填写的菜单路由是product/category</li>
<li>对应的视图是src/view/modules/product/category.vue</li>
</ul>
<h5 id="如何使用多级目录"><a href="#如何使用多级目录" class="headerlink" title="如何使用多级目录"></a>如何使用多级目录</h5><ul>
<li>el-tree中的data是要展示的树形数据</li>
<li>props属性设置</li>
<li>@node-click单击函数</li>
</ul>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">el-tree</span> <span class="attr">:data</span>=<span class="string">&quot;data&quot;</span> <span class="attr">:props</span>=<span class="string">&quot;defaultProps&quot;</span> @<span class="attr">node-click</span>=<span class="string">&quot;handleNodeClick&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">el-tree</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="javascript"></span></span><br><span class="line"><span class="javascript">  <span class="keyword">export</span> <span class="keyword">default</span> &#123;</span></span><br><span class="line"><span class="javascript">    <span class="function"><span class="title">data</span>(<span class="params"></span>)</span> &#123;</span></span><br><span class="line"><span class="javascript">      <span class="keyword">return</span> &#123;</span></span><br><span class="line"><span class="javascript">        <span class="attr">data</span>: [&#123;</span></span><br><span class="line"><span class="javascript">          <span class="attr">label</span>: <span class="string">&#x27;一级 1&#x27;</span>,</span></span><br><span class="line"><span class="javascript">          <span class="attr">children</span>: [&#123;</span></span><br><span class="line"><span class="javascript">            <span class="attr">label</span>: <span class="string">&#x27;二级 1-1&#x27;</span>,</span></span><br><span class="line"><span class="javascript">            <span class="attr">children</span>: [&#123;</span></span><br><span class="line"><span class="javascript">              <span class="attr">label</span>: <span class="string">&#x27;三级 1-1-1&#x27;</span></span></span><br><span class="line"><span class="javascript">            &#125;]</span></span><br><span class="line"><span class="javascript">          &#125;]</span></span><br><span class="line"><span class="javascript">        &#125;, &#123;</span></span><br><span class="line"><span class="javascript">          <span class="attr">label</span>: <span class="string">&#x27;一级 2&#x27;</span>,</span></span><br><span class="line"><span class="javascript">          <span class="attr">children</span>: [&#123;</span></span><br><span class="line"><span class="javascript">            <span class="attr">label</span>: <span class="string">&#x27;二级 2-1&#x27;</span>,</span></span><br><span class="line"><span class="javascript">            <span class="attr">children</span>: [&#123;</span></span><br><span class="line"><span class="javascript">              <span class="attr">label</span>: <span class="string">&#x27;三级 2-1-1&#x27;</span></span></span><br><span class="line"><span class="javascript">            &#125;]</span></span><br><span class="line"><span class="javascript">          &#125;, &#123;</span></span><br><span class="line"><span class="javascript">            <span class="attr">label</span>: <span class="string">&#x27;二级 2-2&#x27;</span>,</span></span><br><span class="line"><span class="javascript">            <span class="attr">children</span>: [&#123;</span></span><br><span class="line"><span class="javascript">              <span class="attr">label</span>: <span class="string">&#x27;三级 2-2-1&#x27;</span></span></span><br><span class="line"><span class="javascript">            &#125;]</span></span><br><span class="line"><span class="javascript">          &#125;]</span></span><br><span class="line"><span class="javascript">        &#125;, &#123;</span></span><br><span class="line"><span class="javascript">          <span class="attr">label</span>: <span class="string">&#x27;一级 3&#x27;</span>,</span></span><br><span class="line"><span class="javascript">          <span class="attr">children</span>: [&#123;</span></span><br><span class="line"><span class="javascript">            <span class="attr">label</span>: <span class="string">&#x27;二级 3-1&#x27;</span>,</span></span><br><span class="line"><span class="javascript">            <span class="attr">children</span>: [&#123;</span></span><br><span class="line"><span class="javascript">              <span class="attr">label</span>: <span class="string">&#x27;三级 3-1-1&#x27;</span></span></span><br><span class="line"><span class="javascript">            &#125;]</span></span><br><span class="line"><span class="javascript">          &#125;, &#123;</span></span><br><span class="line"><span class="javascript">            <span class="attr">label</span>: <span class="string">&#x27;二级 3-2&#x27;</span>,</span></span><br><span class="line"><span class="javascript">            <span class="attr">children</span>: [&#123;</span></span><br><span class="line"><span class="javascript">              <span class="attr">label</span>: <span class="string">&#x27;三级 3-2-1&#x27;</span></span></span><br><span class="line"><span class="javascript">            &#125;]</span></span><br><span class="line"><span class="javascript">          &#125;]</span></span><br><span class="line"><span class="javascript">        &#125;],</span></span><br><span class="line"><span class="javascript">        <span class="attr">defaultProps</span>: &#123;</span></span><br><span class="line"><span class="javascript">          <span class="attr">children</span>: <span class="string">&#x27;children&#x27;</span>,</span></span><br><span class="line"><span class="javascript">          <span class="attr">label</span>: <span class="string">&#x27;label&#x27;</span></span></span><br><span class="line"><span class="javascript">        &#125;</span></span><br><span class="line"><span class="javascript">      &#125;;</span></span><br><span class="line"><span class="javascript">    &#125;,</span></span><br><span class="line"><span class="javascript">    <span class="attr">methods</span>: &#123;</span></span><br><span class="line"><span class="javascript">      <span class="function"><span class="title">handleNodeClick</span>(<span class="params">data</span>)</span> &#123;</span></span><br><span class="line"><span class="javascript">        <span class="built_in">console</span>.log(data);</span></span><br><span class="line"><span class="javascript">      &#125;</span></span><br><span class="line"><span class="javascript">    &#125;</span></span><br><span class="line"><span class="javascript">  &#125;;</span></span><br><span class="line"><span class="javascript"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="八、项目中遇到的困难"><a href="#八、项目中遇到的困难" class="headerlink" title="八、项目中遇到的困难"></a>八、项目中遇到的困难</h2><h3 id="1、登录页验证码不显示的问题"><a href="#1、登录页验证码不显示的问题" class="headerlink" title="1、登录页验证码不显示的问题"></a>1、登录页验证码不显示的问题</h3><p>1、问题发现：</p>
<p>在登录管理后台的时候，F12打开看了一下发现，他要请求<code>localhost:8080/renren-fast/product/category/list/tree</code>这个url路径<br>但是报了404错表示找不到。<br><img src="https://img-blog.csdnimg.cn/img_convert/6cc2c81c35970ad57a7d3608de30771a.png" alt="img"></p>
<p>2、问题出在：他要给8080发请求读取数据，但是数据是在fast 10000端口上</p>
<h3 id="2、解决办法："><a href="#2、解决办法：" class="headerlink" title="2、解决办法："></a>2、解决办法：</h3><p>方法1：改vue项目里的全局配置（不介绍）</p>
<p>方法2：搭建个网关，让网关路由到10000端口（下边方法）</p>
<h5 id="1、解决思路："><a href="#1、解决思路：" class="headerlink" title="1、解决思路："></a>1、解决思路：</h5><p>vue项目的请求给网关，网关url处理后，去nacos找管理后台的微服务，找到对应端口，不需人工管理端口，统一交给网关管理端口接口</p>
<h5 id="2、具体实施："><a href="#2、具体实施：" class="headerlink" title="2、具体实施："></a>2、具体实施：</h5><p>1、修改前端vue的请求路径（在<code>static/config/index.js</code>里）</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"> window.SITE_CONFIG[<span class="string">&#x27;baseUrl&#x27;</span>] = <span class="string">&#x27;http://localhost:88/api&#x27;</span>;</span><br><span class="line"><span class="comment">// 意思是说本vue项目中要请求的资源url都发给88/api，那么我们就让网关端口为88，然后匹配到/api请求即可，</span></span><br><span class="line"><span class="comment">// 网关可以通过过滤器处理url后指定给某个微服务</span></span><br><span class="line"><span class="comment">// renren-fast服务已经注册到了nacos中</span></span><br></pre></td></tr></table></figure>

<p>接着让重新登录htttp://localhost:8001/#/login，验证码是请求88的，所以不显示。而验证码是来源于fast后台的</p>
<p>原始的验证码请求路径：htttp://localhost:**8001/renren-fast/**captcha.jpg?uuid=69c79f02-d15b-478a-8465-a07fd09001e6<br>现在的验证码请求路径为，htttp://localhst:**88/api/**captcha.jpg?uuid=69c79f02-d15b-478a-8465-a07fd09001e6</p>
<p>2、把gateway注册到Nacos中（配置网关端口）</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"># gateway微服务的配置</span><br><span class="line">spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848</span><br><span class="line">spring.application.name=gulimall-gateway</span><br><span class="line">server.port=88</span><br></pre></td></tr></table></figure>

<p>3、把fast注册到Nacos（请求网关88——&gt;fast8080）</p>
<p>（1）fast项目中添加注册中心的依赖（而common中有Nacos依赖，所以引入common）</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 里面有nacos注册中心 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.atguigu.gulimall<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>gulimall-common<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>0.0.1-SNAPSHOT<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span> </span><br></pre></td></tr></table></figure>

<p>（2）renren-fast项目中添加配置文件</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">application:</span></span><br><span class="line">    <span class="attr">name:</span> <span class="string">renren-fast</span>  <span class="comment"># 意思是把renren-fast项目也注册到nacos中(后面不再强调了)，这样网关才能转发给</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">nacos:</span></span><br><span class="line">      <span class="attr">discovery:</span></span><br><span class="line">        <span class="attr">server-addr:</span> <span class="string">localhost:8848</span> <span class="comment"># nacos       </span></span><br><span class="line"><span class="attr">server:</span> </span><br><span class="line">  <span class="attr">port:</span> <span class="number">88</span>  <span class="comment"># 别和gateway冲突了</span></span><br></pre></td></tr></table></figure>

<p>3、然后在fast启动类上加上注解<code>@EnableDiscoveryClient</code>，重启在nacos的服务列表里看到了renren-fast</p>
<p>​        如果报错gson依赖，就导入google的gson依赖</p>
<p>4、gateway中网关-路径重写配置</p>
<p>（1）重写1</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="bullet">-</span> <span class="attr">id:</span> <span class="string">admin_route</span></span><br><span class="line">  <span class="attr">uri:</span> <span class="string">lb://renren-fast</span> <span class="comment"># 路由：给renren-fast，lb代表负载均衡</span></span><br><span class="line">  <span class="attr">predicates:</span>  <span class="comment">#断言：什么情况下路由给它</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">Path=/api/**</span> <span class="comment"># 默认前端项目都带上api前缀，就是我们前面题的localhost:88/api</span></span><br><span class="line">  <span class="attr">filters:</span></span><br><span class="line">    <span class="bullet">-</span> <span class="string">RewritePath=/api/(?&lt;segment&gt;.*),/renren-fast/$\&#123;segment&#125;</span>  <span class="comment"># 过滤：把/api/* 改变成 /renren-fast/*</span></span><br></pre></td></tr></table></figure>

<p>修改过vue后验证码请求的是：htttp://<strong>localhost:88/api</strong>/captcha.jpg</p>
<p>重写1后找到后拼接成了        ： htttp://<strong>renren-fast:8080/api</strong>/captcha.jpg</p>
<p>（2）重写2</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="bullet">-</span> <span class="attr">id:</span> <span class="string">admin_route</span></span><br><span class="line">       <span class="attr">uri:</span> <span class="string">lb://renren-fast</span></span><br><span class="line">       <span class="attr">predicates:</span></span><br><span class="line">         <span class="bullet">-</span> <span class="string">Path=/api/**</span></span><br><span class="line">       <span class="attr">filters:</span></span><br><span class="line">         <span class="bullet">-</span> <span class="string">RewritePath=/api/(?&lt;segment&gt;.*),/renren-fast/$\&#123;segment&#125;</span></span><br></pre></td></tr></table></figure>

<h2 id="九、跨域问题"><a href="#九、跨域问题" class="headerlink" title="九、跨域问题"></a>九、跨域问题</h2><h3 id="1、跨域问题发现"><a href="#1、跨域问题发现" class="headerlink" title="1、跨域问题发现"></a>1、跨域问题发现</h3><p>登录，还是报错：（出现了跨域的问题，就是说vue项目是8001端口，却要跳转到88端口，为了安全性，不可以）</p>
<p><img src="https://img-blog.csdnimg.cn/img_convert/ee0325699356d0fa62e3a1c8adf1bc16.png" alt="img"></p>
<h3 id="2、什么是跨域问题"><a href="#2、什么是跨域问题" class="headerlink" title="2、什么是跨域问题"></a>2、什么是跨域问题</h3><ul>
<li>跨域：指的是浏览器不能执行其他网站的脚本。它是由浏览器的同源策略造成的，是浏览器对js施加的安全限制。（ajax可以）</li>
<li>同源策略：是指<code>协议，域名，端囗</code>都要相同，其中有一个不同都会产生跨域；</li>
</ul>
<p>这里问题：同源策略禁止8001端口页面读取位于 htttp://localhost:88/api/sys/login 的远程资源。访问的域名或端口和原来请求的域名端口一旦不同，请求就会被限制（原因：CORS 头缺少 ‘Access-Control-Allow-Origin’）</p>
<h3 id="3、跨域的流程"><a href="#3、跨域的流程" class="headerlink" title="3、跨域的流程"></a>3、跨域的流程</h3><p>跨域是要请求的、新的端口那个服务器限制的，不是浏览器限制的。</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">跨域请求流程：</span><br><span class="line">非简单请求(PUT、DELETE)等，需要先发送预检请求</span><br><span class="line">       -----1、预检请求、OPTIONS ------&gt;</span><br><span class="line">       &lt;----2、服务器响应允许跨域 ------</span><br><span class="line">浏览器 |                               |  服务器</span><br><span class="line">       -----3、正式发送真实请求 --------&gt;</span><br><span class="line">       &lt;----4、响应数据   --------------</span><br></pre></td></tr></table></figure>

<h3 id="4、跨域的解决方案"><a href="#4、跨域的解决方案" class="headerlink" title="4、跨域的解决方案"></a>4、跨域的解决方案</h3><h4 id="解决方案1："><a href="#解决方案1：" class="headerlink" title="解决方案1："></a>解决方案1：</h4><p>设置nginx包含admin和gateway。都先请求nginx，这样端口就统一了</p>
<img src="https://img-blog.csdnimg.cn/img_convert/ad158721a7490708ba0ec7cfb03333a4.png" alt="img" style="zoom: 67%;" />

<h4 id="解决方案2："><a href="#解决方案2：" class="headerlink" title="解决方案2："></a>解决方案2：</h4><p>让服务器告诉预检请求能跨域（在<strong>服务端2</strong>配置允许跨域）</p>
<p>1、在网关中定义“<code>GulimallCorsConfiguration</code>”类，该类用来做过滤，允许所有的请求跨域。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.atguigu.gulimall.gateway.config;</span><br><span class="line"></span><br><span class="line"><span class="meta">@Configuration</span> <span class="comment">// gateway</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">GulimallCorsConfiguration</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Bean</span> <span class="comment">// 添加过滤器</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> CorsWebFilter <span class="title">corsWebFilter</span><span class="params">()</span></span>&#123;</span><br><span class="line">        <span class="comment">// 基于url跨域，选择reactive包下的</span></span><br><span class="line">        UrlBasedCorsConfigurationSource source=<span class="keyword">new</span> UrlBasedCorsConfigurationSource();</span><br><span class="line">        <span class="comment">// 跨域配置信息</span></span><br><span class="line">        CorsConfiguration corsConfiguration = <span class="keyword">new</span> CorsConfiguration();</span><br><span class="line">        <span class="comment">// 允许跨域的头</span></span><br><span class="line">        corsConfiguration.addAllowedHeader(<span class="string">&quot;*&quot;</span>);</span><br><span class="line">        <span class="comment">// 允许跨域的请求方式</span></span><br><span class="line">        corsConfiguration.addAllowedMethod(<span class="string">&quot;*&quot;</span>);</span><br><span class="line">        <span class="comment">// 允许跨域的请求来源</span></span><br><span class="line">        corsConfiguration.addAllowedOrigin(<span class="string">&quot;*&quot;</span>);</span><br><span class="line">        <span class="comment">// 是否允许携带cookie跨域</span></span><br><span class="line">        corsConfiguration.setAllowCredentials(<span class="keyword">true</span>);</span><br><span class="line">        <span class="comment">// 任意url都要进行跨域配置</span></span><br><span class="line">        source.registerCorsConfiguration(<span class="string">&quot;/**&quot;</span>,corsConfiguration);</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> CorsWebFilter(source);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>2、再次访问：htttp://localhost:8001/#/login</p>
<p><img src="https://img-blog.csdnimg.cn/img_convert/8270103b813b10c3d4a1bd7138bc9e85.png" alt="img"></p>
<p>再次出现问题：已拦截跨源请求：同源策略禁止读取位于 htttp://localhost:88/api/sys/login 的远程资源。</p>
<p>（原因：不允许有多个 ‘Access-Control-Allow-Origin’ CORS 头）</p>
<p>出现了多个请求，并且也存在多个跨源请求。</p>
<p>为了解决这个问题，需要修改renren-fast项目，注释掉“io.renren.config.CorsConfig”类。然后再次进行访问。</p>
<h2 id="十、product请求路径重写"><a href="#十、product请求路径重写" class="headerlink" title="十、product请求路径重写"></a>十、product请求路径重写</h2><p>之前解决了登录验证码的问题，/api/请求重写成了/renren-fast，但是vue项目中或者你自己写的数据库中有些是以/product为前缀的，它要请求product微服务，你要也让它请求renren-fast显然是不合适的。</p>
<p>解决办法是把请求在网关中以更小的范围先拦截一下，剩下的请求再交给renren-fast</p>
<p>在显示商品系统/分类信息的时候，出现了404异常，请求的htttp://localhost:88/api/product/category/list/tree不存在</p>
<p><img src="https://img-blog.csdnimg.cn/img_convert/87437ce67f22d4531db230027ac45bfd.png" alt="img"></p>
<p>网关所做的路径映射不正确，映射后路径为：htttp://**localhost:8001/renren-fast/**product/category/list/tree</p>
<p>所以会报404异常，但是只有通过                 ：htttp://**localhost:10000/**product/category/list/tree路径才能够正常访问，<br>解决方法就是定义一个product路由规则，进行路径重写：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="bullet">-</span> <span class="attr">id:</span> <span class="string">product_route</span></span><br><span class="line">  <span class="attr">uri:</span> <span class="string">lb://gulimall-product</span> <span class="comment"># 注册中心的服务</span></span><br><span class="line">  <span class="attr">predicates:</span></span><br><span class="line">    <span class="bullet">-</span> <span class="string">Path=/api/product/**</span></span><br><span class="line">  <span class="attr">filters:</span></span><br><span class="line">    <span class="bullet">-</span> <span class="string">RewritePath=/api/(?&lt;segment&gt;/?.*),/$\&#123;segment&#125;</span></span><br></pre></td></tr></table></figure>

<p>product项目的application.yml</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">datasource:</span></span><br><span class="line">    <span class="attr">username:</span> <span class="string">root</span></span><br><span class="line">    <span class="attr">password:</span> <span class="string">root</span></span><br><span class="line">    <span class="attr">url:</span> <span class="string">jdbc:mysql://192.168.56.10:3306/guli_pms?useUnicode=true&amp;characterEncoding=UTF-8&amp;useSSL=false&amp;serverTimezone=Asia/Shanghai</span></span><br><span class="line">    <span class="attr">driver-class-name:</span> <span class="string">com.mysql.cj.jdbc.Driver</span></span><br><span class="line">  <span class="attr">cloud:</span></span><br><span class="line">    <span class="attr">nacos:</span></span><br><span class="line">      <span class="attr">discovery:</span></span><br><span class="line">        <span class="attr">server-addr:</span> <span class="string">localhost:8848</span></span><br><span class="line"></span><br><span class="line"><span class="attr">mybatis-plus:</span></span><br><span class="line">  <span class="attr">mapper-locations:</span> <span class="string">classpath:/mapper/**/*.xml</span></span><br><span class="line">  <span class="attr">global-config:</span></span><br><span class="line">    <span class="attr">db-config:</span></span><br><span class="line">      <span class="attr">id-type:</span> <span class="string">auto</span></span><br><span class="line">      <span class="attr">logic-delete-value:</span> <span class="number">1</span></span><br><span class="line">      <span class="attr">logic-not-delete-value:</span> <span class="number">0</span></span><br><span class="line"></span><br><span class="line"><span class="attr">server:</span></span><br><span class="line">  <span class="attr">port:</span> <span class="number">10001</span></span><br></pre></td></tr></table></figure>

<p>nacos配置中心：nacos中新建命名空间，用命名空间隔离项目，(可以在其中新建gulimall-product.yml)<br>product项目中新建bootstrap.properties</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">spring.application.name=gulimall-product</span><br><span class="line">spring.cloud.nacos.config.server-addr=127.0.0.1:8848</span><br><span class="line">spring.cloud.nacos.config.namespace=e6cd36a8-81a2-4df2-bfbc-f0524fa17664</span><br></pre></td></tr></table></figure>

<p>+6</p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">SuJin</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://sujiesujie12456789.gitee.io/2021/11/30/%E4%B9%90%E4%BA%AB%E8%B4%AD%E9%A1%B9%E7%9B%AE/">https://sujiesujie12456789.gitee.io/2021/11/30/%E4%B9%90%E4%BA%AB%E8%B4%AD%E9%A1%B9%E7%9B%AE/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://sujiesujie12456789.gitee.io" target="_blank">SuJin博客</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"><div class="social-share" data-image="https://picsum.photos/id/862/5451/3634" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2021/12/18/%E6%88%91%E7%9A%84%E7%AC%AC%E4%B8%80%E7%AF%87%E5%8D%9A%E5%AE%A2/"><img class="prev-cover" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">MySQL学习笔记</div></div></a></div><div class="next-post pull-right"><a href="/2021/08/30/Git/"><img class="next-cover" src="https://picsum.photos/id/862/5451/3634" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Git</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="http://picsum.photos/id/859/1919/1919" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">SuJin</div><div class="author-info__description">SuJin的博客，欢迎访问</div></div><div class="card-info-data is-center"><div class="card-info-data-item"><a href="/archives/"><div class="headline">文章</div><div class="length-num">11</div></a></div><div class="card-info-data-item"><a href="/tags/"><div class="headline">标签</div><div class="length-num">0</div></a></div><div class="card-info-data-item"><a href="/categories/"><div class="headline">分类</div><div class="length-num">0</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://gitee.com/sujin1125" target="_blank" title="Gitee"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:sujin_a@163.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a><a class="social-icon" href="https://sujin1125.gitee.io/" target="_blank" title="博客"><i class="fab fa-algolia"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E7%AC%94%E8%AE%B03"><span class="toc-number">1.</span> <span class="toc-text">笔记3</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8Spring-Boot%E5%BC%80%E5%8F%91%E5%BE%AE%E6%9C%8D%E5%8A%A1%EF%BC%8C"><span class="toc-number">1.0.0.1.</span> <span class="toc-text">使用Spring Boot开发微服务，</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%80%E3%80%81git%E4%BB%A3%E7%A0%81%E7%9B%B8%E5%85%B3"><span class="toc-number">1.1.</span> <span class="toc-text">一、git代码相关</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1%E3%80%81%E5%AE%89%E8%A3%85git"><span class="toc-number">1.1.1.</span> <span class="toc-text">1、安装git</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2%E3%80%81%E4%BB%8E0%E6%90%AD%E5%BB%BA"><span class="toc-number">1.1.2.</span> <span class="toc-text">2、从0搭建</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%85%B1%E5%90%8C%E7%82%B9%EF%BC%9A"><span class="toc-number">1.1.2.0.1.</span> <span class="toc-text">共同点：</span></a></li></ol></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BA%8C%E3%80%81SpringCloud-Alibaba%E7%AE%80%E4%BB%8B"><span class="toc-number">1.2.</span> <span class="toc-text">二、SpringCloud Alibaba简介</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%89%E3%80%81Nacos%E6%B3%A8%E5%86%8C%E4%B8%AD%E5%BF%83"><span class="toc-number">1.3.</span> <span class="toc-text">三、Nacos注册中心</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1%E3%80%81%E5%AE%89%E8%A3%85%E5%90%AF%E5%8A%A8nacos%EF%BC%9A"><span class="toc-number">1.3.0.1.</span> <span class="toc-text">1、安装启动nacos：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2%E3%80%81nacos%E4%BD%BF%E7%94%A8%EF%BC%9A"><span class="toc-number">1.3.0.2.</span> <span class="toc-text">2、nacos使用：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3%E3%80%81nacos%E6%B5%8B%E8%AF%95%EF%BC%9A"><span class="toc-number">1.3.0.3.</span> <span class="toc-text">3、nacos测试：</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%9B%9B%E3%80%81Feign%E8%BF%9C%E7%A8%8B%E8%B0%83%E7%94%A8"><span class="toc-number">1.4.</span> <span class="toc-text">四、Feign远程调用</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%EF%BC%88%E2%80%94%EF%BC%89%E3%80%81%E4%BC%98%E6%83%A0%E5%88%B8coupon%E9%83%A8%E5%88%86"><span class="toc-number">1.4.1.</span> <span class="toc-text">（—）、优惠券coupon部分</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1%E3%80%81pom-xml"><span class="toc-number">1.4.1.1.</span> <span class="toc-text">1、pom.xml</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2%E3%80%81%E6%8E%A7%E5%88%B6%E5%B1%82"><span class="toc-number">1.4.1.2.</span> <span class="toc-text">2、控制层</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%EF%BC%88%E4%BA%8C%EF%BC%89%E3%80%81%E4%BC%9A%E5%91%98member%E9%83%A8%E5%88%86%E5%86%85%E5%AE%B9"><span class="toc-number">1.4.2.</span> <span class="toc-text">（二）、会员member部分内容</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1%E3%80%81%E9%85%8D%E7%BD%AE%E7%B1%BB"><span class="toc-number">1.4.2.1.</span> <span class="toc-text">1、配置类</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2%E3%80%81%E6%96%B0%E5%BB%BA%E7%B1%BB%EF%BC%9A"><span class="toc-number">1.4.2.2.</span> <span class="toc-text">2、新建类：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3%E3%80%81%E6%B5%8B%E8%AF%95%E8%AF%B7%E6%B1%82"><span class="toc-number">1.4.2.3.</span> <span class="toc-text">3、测试请求</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#4%E3%80%81%E6%B5%8B%E8%AF%95%EF%BC%9A"><span class="toc-number">1.4.2.4.</span> <span class="toc-text">4、测试：</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BA%94%E3%80%81nacos%E9%85%8D%E7%BD%AE%E4%B8%AD%E5%BF%83"><span class="toc-number">1.5.</span> <span class="toc-text">五、nacos配置中心</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1%E3%80%81nacos%E4%BD%9C%E4%B8%BA%E9%85%8D%E7%BD%AE%E4%B8%AD%E5%BF%83%E3%80%82"><span class="toc-number">1.5.1.</span> <span class="toc-text">1、nacos作为配置中心。</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2%E3%80%81%E9%85%8D%E7%BD%AE%E4%B8%AD%E5%BF%83%E8%BF%9B%E9%98%B6"><span class="toc-number">1.5.2.</span> <span class="toc-text">2、配置中心进阶</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%85%AD%E3%80%81%E7%BD%91%E5%85%B3gateway-88"><span class="toc-number">1.6.</span> <span class="toc-text">六、网关gateway-88</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1%E3%80%81%E4%BD%9C%E7%94%A8"><span class="toc-number">1.6.1.</span> <span class="toc-text">1、作用</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2%E3%80%81%E4%B8%89%E5%A4%A7%E6%A0%B8%E5%BF%83%E6%A6%82%E5%BF%B5%EF%BC%9A"><span class="toc-number">1.6.2.</span> <span class="toc-text">2、三大核心概念：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3%E3%80%81%E6%80%BB%E6%A6%82%E8%A7%88"><span class="toc-number">1.6.3.</span> <span class="toc-text">3、总概览</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#1%E3%80%81%E9%85%8D%E7%BD%AEnacos%E6%B3%A8%E5%86%8C%E4%B8%AD%E5%BF%83"><span class="toc-number">1.6.3.0.0.1.</span> <span class="toc-text">1、配置nacos注册中心</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#2%E3%80%81%E9%85%8D%E7%BD%AEnacos%E9%85%8D%E7%BD%AE%E4%B8%AD%E5%BF%83%E5%9C%B0%E5%9D%80"><span class="toc-number">1.6.3.0.0.2.</span> <span class="toc-text">2、配置nacos配置中心地址</span></a></li></ol></li></ol></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%83%E3%80%81%E4%B8%89%E7%BA%A7%E5%88%86%E7%B1%BB"><span class="toc-number">1.7.</span> <span class="toc-text">七、三级分类</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1%E3%80%81%E5%90%AF%E5%8A%A8%E9%A1%B9%E7%9B%AE%E7%8E%AF%E5%A2%83"><span class="toc-number">1.7.0.1.</span> <span class="toc-text">1、启动项目环境</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2%E3%80%81element-ui%E7%9A%84%E4%BD%BF%E7%94%A8"><span class="toc-number">1.7.0.2.</span> <span class="toc-text">2、element-ui的使用</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3%E3%80%81pms-category%EF%BC%88%E5%95%86%E5%93%81%E7%9A%84%E5%88%86%E7%B1%BB%EF%BC%89%E4%B8%BA%E4%BE%8B%E8%AF%B4%E6%98%8E"><span class="toc-number">1.7.0.3.</span> <span class="toc-text">3、pms_category（商品的分类）为例说明</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#1%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93%E6%90%AD%E5%BB%BA"><span class="toc-number">1.7.0.3.1.</span> <span class="toc-text">1、数据库搭建</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#4%E3%80%81%E6%8E%A5%E7%9D%80%E6%93%8D%E4%BD%9C%E5%90%8E%E5%8F%B0"><span class="toc-number">1.7.0.4.</span> <span class="toc-text">4、接着操作后台</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E8%8F%9C%E5%8D%95%E8%B7%AF%E7%94%B1"><span class="toc-number">1.7.0.4.1.</span> <span class="toc-text">菜单路由</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%E5%A4%9A%E7%BA%A7%E7%9B%AE%E5%BD%95"><span class="toc-number">1.7.0.4.2.</span> <span class="toc-text">如何使用多级目录</span></a></li></ol></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%85%AB%E3%80%81%E9%A1%B9%E7%9B%AE%E4%B8%AD%E9%81%87%E5%88%B0%E7%9A%84%E5%9B%B0%E9%9A%BE"><span class="toc-number">1.8.</span> <span class="toc-text">八、项目中遇到的困难</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1%E3%80%81%E7%99%BB%E5%BD%95%E9%A1%B5%E9%AA%8C%E8%AF%81%E7%A0%81%E4%B8%8D%E6%98%BE%E7%A4%BA%E7%9A%84%E9%97%AE%E9%A2%98"><span class="toc-number">1.8.1.</span> <span class="toc-text">1、登录页验证码不显示的问题</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2%E3%80%81%E8%A7%A3%E5%86%B3%E5%8A%9E%E6%B3%95%EF%BC%9A"><span class="toc-number">1.8.2.</span> <span class="toc-text">2、解决办法：</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#1%E3%80%81%E8%A7%A3%E5%86%B3%E6%80%9D%E8%B7%AF%EF%BC%9A"><span class="toc-number">1.8.2.0.1.</span> <span class="toc-text">1、解决思路：</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#2%E3%80%81%E5%85%B7%E4%BD%93%E5%AE%9E%E6%96%BD%EF%BC%9A"><span class="toc-number">1.8.2.0.2.</span> <span class="toc-text">2、具体实施：</span></a></li></ol></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B9%9D%E3%80%81%E8%B7%A8%E5%9F%9F%E9%97%AE%E9%A2%98"><span class="toc-number">1.9.</span> <span class="toc-text">九、跨域问题</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1%E3%80%81%E8%B7%A8%E5%9F%9F%E9%97%AE%E9%A2%98%E5%8F%91%E7%8E%B0"><span class="toc-number">1.9.1.</span> <span class="toc-text">1、跨域问题发现</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2%E3%80%81%E4%BB%80%E4%B9%88%E6%98%AF%E8%B7%A8%E5%9F%9F%E9%97%AE%E9%A2%98"><span class="toc-number">1.9.2.</span> <span class="toc-text">2、什么是跨域问题</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3%E3%80%81%E8%B7%A8%E5%9F%9F%E7%9A%84%E6%B5%81%E7%A8%8B"><span class="toc-number">1.9.3.</span> <span class="toc-text">3、跨域的流程</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4%E3%80%81%E8%B7%A8%E5%9F%9F%E7%9A%84%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88"><span class="toc-number">1.9.4.</span> <span class="toc-text">4、跨域的解决方案</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%881%EF%BC%9A"><span class="toc-number">1.9.4.1.</span> <span class="toc-text">解决方案1：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%882%EF%BC%9A"><span class="toc-number">1.9.4.2.</span> <span class="toc-text">解决方案2：</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8D%81%E3%80%81product%E8%AF%B7%E6%B1%82%E8%B7%AF%E5%BE%84%E9%87%8D%E5%86%99"><span class="toc-number">1.10.</span> <span class="toc-text">十、product请求路径重写</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2022/04/15/java%E7%AC%94%E8%AF%95%E9%A2%98%E6%80%BB%E7%BB%93/" title="“java笔试题总结”"><img src="https://picsum.photos/id/862/5451/3634" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="“java笔试题总结”"/></a><div class="content"><a class="title" href="/2022/04/15/java%E7%AC%94%E8%AF%95%E9%A2%98%E6%80%BB%E7%BB%93/" title="“java笔试题总结”">“java笔试题总结”</a><time datetime="2022-04-15T07:53:41.000Z" title="发表于 2022-04-15 15:53:41">2022-04-15</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/03/30/Nginx/" title="Nginx"><img src="https://picsum.photos/id/862/5451/3634" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Nginx"/></a><div class="content"><a class="title" href="/2022/03/30/Nginx/" title="Nginx">Nginx</a><time datetime="2022-03-30T14:01:07.000Z" title="发表于 2022-03-30 22:01:07">2022-03-30</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/03/30/SpringMVC%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" title="SpringMVC学习笔记"><img src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="SpringMVC学习笔记"/></a><div class="content"><a class="title" href="/2022/03/30/SpringMVC%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" title="SpringMVC学习笔记">SpringMVC学习笔记</a><time datetime="2022-03-30T13:35:27.000Z" title="发表于 2022-03-30 21:35:27">2022-03-30</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/03/30/MyBatis/" title="MyBatis学习"><img src="https://picsum.photos/id/862/5451/3634" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="MyBatis学习"/></a><div class="content"><a class="title" href="/2022/03/30/MyBatis/" title="MyBatis学习">MyBatis学习</a><time datetime="2022-03-30T13:08:22.000Z" title="发表于 2022-03-30 21:08:22">2022-03-30</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/12/18/redis/" title="redis笔记"><img src="https://picsum.photos/id/862/5451/3634" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="redis笔记"/></a><div class="content"><a class="title" href="/2021/12/18/redis/" title="redis笔记">redis笔记</a><time datetime="2021-12-18T12:47:07.000Z" title="发表于 2021-12-18 20:47:07">2021-12-18</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2022 By SuJin</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>